package com.ssmTmp.learn;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class ExecuteAspect {

    //@Before是在所拦截方法执行之前执行一段逻辑
    // @Before(value = "com.ssmTmp.api.aspects.AopConfigCenter.executePoint()")
    public void methodBefore() {
        log.info("=================执行了前置切面方法=================");
    }

    //@After 是在所拦截方法执行之后执行一段逻辑
    // @After(value = "com.ssmTmp.api.aspects.AopConfigCenter.executePoint()")
    public void methodAfter() {
        log.info("=================执行了后置切面方法=================");
    }

    // @AfterReturning(returning = "rtObject", value = "com.ssmTmp.api.aspects.AopConfigCenter.executePoint()")
    public void methodAfterReturn(Object rtObject) {
        System.out.println("=================后置切面返回结果=================");
        System.out.println(JSON.toJSON(rtObject));
    }

    //@Around是可以同时在所拦截方法的前后执行一段逻辑
    @Around(value = "com.ssmTmp.learn.AopConfigCenter.executePoint()")
    public void methodAround(ProceedingJoinPoint pjp) {
        Object proceed = null;
        try {
            proceed = pjp.proceed();
            System.out.println(JSON.toJSON(proceed));
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        System.out.println("=================环绕切点=================");
    }

}
